package com.raven.craft.code.generator.mysql.mybatis;

import com.raven.craft.code.generator.config.JavaFileProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

/**
 * @author raven
 * @date 2019-05-31 18:52
 */
@Getter
@Setter
@ToString
@ConfigurationProperties(prefix = "generator.mysql.mybatis")
public class MyBatisProperties extends JavaFileProperties {

    private String trimPrefix;
    private String trimSuffix;

    private String entityTemplatePath = "/templates/mybatis/entity";
    private String mapperTemplatePath = "/templates/mybatis/mapper";
    private String serviceTemplatePath = "/templates/mybatis/service";
    private String voTemplatePath = "/templates/mybatis/vo";

    private String entityPackage;
    private String mapperPackage;
    private String servicePackage;
    private String voPackage;

    public String getEntityPackage() {
        if (StringUtils.isEmpty(entityPackage)) {
            entityPackage = getPackage("entity");
        }
        return entityPackage;
    }

    public String getMapperPackage() {
        if (StringUtils.isEmpty(mapperPackage)) {
            mapperPackage = getPackage("mapper");
        }
        return mapperPackage;
    }

    public String getServicePackage() {
        if (StringUtils.isEmpty(servicePackage)) {
            servicePackage = getPackage("service");
        }
        return servicePackage;
    }

    public String getVoPackage() {
        if (StringUtils.isEmpty(voPackage)) {
            voPackage = getPackage("vo");
        }
        return voPackage;
    }

    private String getPackage(String slice) {
        if (StringUtils.isEmpty(getTargetPackage())) {
            return slice;
        }
        return getTargetPackage() + "." + slice;
    }
}
